import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    //2.添加重定向,用户访问http://localhost:8080/时跳转到 http://localhost:8080/index 首页去
    redirect:'/index',
    //1.添加4个页面的路径
    children:[
      {path: '/reg', component: () => import( '../views/home/RegView.vue')},
      {path: '/login', component: () => import( '../views/home/LoginView.vue')},
      {path: '/index', component: () => import( '../views/home/IndexView.vue')},
      {path: '/detail', component: () => import( '../views/home/DetailView.vue')}
    ]
  }//3.给新增的/views/AdminView.vue文件配置路由
  ,
  {
    path: '/admin',
    //箭头函数：【懒加载:用到了再加载】
    //文件的后缀名.vue可以省略不写
    component: () => import( '../views/AdminView'),
    //4.添加刚刚新增的3个页面的路径
    children:[
      //path:'/' 这里的'/'指的是工程的根目录，也就是http://localhost:8080/
      //path为 '/user'的效果是 localhost:8080/user 路径不对,可写为'/admin/user'
      //所以可以不写斜杠'/',那么'user'的效果是 localhost:8080/admin/user
      {path:'user',component:()=>import('../views/admin/UserView')},
      {path:'banner',component:()=>import('../views/admin/BannerView')},
      {path:'product',component:()=>import('../views/admin/ProductView')}
    ]
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router
